import request from '@/utils/request'

const baseURL = '/shop'

// 新增商店
export const addIdentity = (data) =>
  request.post(`${baseURL}/addIdentity`, data, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  })

// 获取商店
export const getIdentity = (id) => request.get(`${baseURL}/getIdentity`)

// 获取商店简略信息
export const getIdentityPreview = () => request.get(`${baseURL}/getIdentityPreview`)

// 根据id查找商店
export const getIdentityById = (id) =>
  request.get(`${baseURL}/getIdentityById`, {
    params: {
      id,
    },
  })

// 更新商店
export const updateIdentity = (data) =>
  request.post(`${baseURL}/updateIdentity`, data, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  })

// 删除商店
export const deleteIdentity = (id) =>
  request.get(`${baseURL}/deleteIdentity`, {
    params: {
      id,
    },
  })

// 增加商品
export const addGoods = (data) =>
  request.post(`${baseURL}/addGood`, data, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  })

// 获取当前用户商品
export const getGoods = (page, isSave) =>
  request.get(`${baseURL}/getGoods`, {
    params: {
      page,
      size: 6,
      isSave,
    },
  })

// 获取商品
export const getGoodsRandom = (page) =>
  request.get(`${baseURL}/getGoodsRandom`, {
    params: {
      page,
      size: 6,
    },
  })

// 获取商品详细信息
export const getGoodsDetail = (id) =>
  request.get(`${baseURL}/getGoodDetail`, {
    params: {
      id,
    },
  })

// 发布评论
export const postComment = (data) => request.post(`${baseURL}/postComment`, data)

// 获取商品所有评论
export const getComments = (id) =>
  request.get(`${baseURL}/getComments`, {
    params: {
      id,
    },
  })

// 点赞评论
export const thumbsUpShopComment = (id) =>
  request.get(`${baseURL}/thumbsUp`, {
    params: {
      id,
    },
  })

// 删除评论
export const deleteGoodComment = (id) =>
  request.get(`${baseURL}/deleteGoodComment`, {
    params: {
      id,
    },
  })

// 判断用户是否点赞
export const isUserLikeShopComment = (id) =>
  request.get(`${baseURL}/isUserLikeShopComment`, {
    params: {
      id,
    },
  })

// 获取当前用户所有地址
export const getAllAddress = () => request.get(`${baseURL}/getAllAddress`)

// 新增地址
export const addNewAddress = (data) => request.post(`${baseURL}/addNewAddress`, data)

// 自动补全地址
export const getCurrentAddress = () => request.get(`${baseURL}/getCurrentAddress`)

// 更新地址信息
export const updateAddress = (data) => request.post(`${baseURL}/updateAddress`, data)

// 添加到购物车
export const addGoodToCart = (id) =>
  request.get(`${baseURL}/addGoodToCart`, {
    params: {
      id,
    },
  })

// 从购物车删除商品
export const deleteGoodFromCart = (id) =>
  request.get(`${baseURL}/deleteGoodFromCart`, {
    params: {
      id,
    },
  })

// 获取购物车信息
export const getGoodsFromCart = () => request.get(`${baseURL}/getGoodsFromCart`)

// 确认订单
export const addOrder = (data) => request.post(`${baseURL}/addOrder`, data)

// 获取用户所有订单
export const getOrder = () => request.get(`${baseURL}/getOrder`)

// 搜索商品
export const searchGood = (word) =>
  request.get(`${baseURL}/searchGood`, {
    params: {
      search: word,
    },
  })
